package BanyuanClub.Work.Day0309.练习.烤汉堡;

public class Guest {
    private Waiter waiter;
    public Guest(Waiter waiter){
        this.waiter = waiter;
    }
    public void eat(){
        Thread th = new Thread(() -> {
            try {
                int n = 0;
            for (int i = 0; i < 20/2; i++) {
                Thread.sleep(2000);
                if (waiter.getShou() > 0){
                waiter.setShou(waiter.getShou() - 1);
                System.out.println("老子吃了个汉堡");
                n += 1;
                }
            }
                System.out.println("老子吃了" + n +"个汉堡");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread th1 = new Thread(() -> {
            try {
                int n = 0;
                for (int i = 0; i < 20/3 ; i++) {
                    Thread.sleep(3000);
                    if (waiter.getShou() > 0){
                    waiter.setShou(waiter.getShou() - 1);
                    System.out.println("孙子吃了个汉堡");
                    n += 1;
                    }
                }
                System.out.println("孙子吃了" + n + "个汉堡");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        th.start();
        th1.start();

    }
}
